﻿//==================================================================
// Copyright (C) 2011 iSun Studio 软件工作室
// 文件名: SelfDefineTree.cs
// 作 者：张骁晓
// 日 期：2012-03-15 09:37
// 描 述：根据传入的类型创建不同的类型树
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Text;
using iSun.BLL.Base;
using System.Web.UI.WebControls;
using System.ComponentModel;
using iSun.BLL;
using iSun.Entity;
namespace iSun.Web.UI.Controls
{


    public class SelfDefineTree : Literal
    {
        //类型
        private string _TreeType = "";
        [Description("需要创建的树的类型")]
        public string TreeType
        {
            get { return _TreeType; }
            set { _TreeType = value; }
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            string content = "";
            if (!DesignMode)
            {
                switch (TreeType.ToLower())
                {
                    case "course": content = CreateCourseTree(); //课程树
                        break;
                    case "productlayout": content = CreateProductLayoutTree();
                        break;
                }
            }
            writer.Write(content);
            base.Render(writer);
        }

        #region 创建产品树
        private string CreateCourseTree()
        {
            //得到课程类型
            StringBuilder _strHtml = new StringBuilder();
            BDatPhraseDetail productTypeMgr = new BDatPhraseDetail();
            IList<DatPhraseDetail> ilist = productTypeMgr.GetDatPhraseDetailByClassValue("ProductType");
            _strHtml.Append("<div  id='" + this.ID + "' class='whitebg'>");
            _strHtml.Append("<ul>");
            _strHtml.Append("<li><a href='#'>产品类型</a>");
            if (ilist != null && ilist.Count > 0)
            {
                _strHtml.Append("<ul>");
                //添加产品类型
                foreach (DatPhraseDetail v in ilist)
                {
                    _strHtml.Append("<li>");
                    _strHtml.Append("<a href=\"#" + v.PhraseID + "\">" + v.PhraseText + "</a>");
                    //添加产品节点
                    addCourse(v.PhraseID, _strHtml);
                    _strHtml.Append("</li>");
                }
                _strHtml.Append("</ul>");
            }
            _strHtml.Append("</li></ul>");
           _strHtml.Append("</div>");
            return _strHtml.ToString();

        }
        //添加产品节点到产品树
        private void addCourse(Guid productTypeId, StringBuilder sb)
        {
            //BaseBussnies bll = new BaseBussnies();
            //IList<CrmProduct> ilist = bll.GetEntitys<CrmProduct>("TypeId='" + productTypeId + "'");
            //if (ilist != null && ilist.Count > 0)
            //{
            //    sb.Append("<ul>");
            //    foreach (CrmProduct v in ilist)
            //    {
            //        sb.Append("<li>");
            //        sb.Append("<span><a href=\"#" + v.Productid + "\" style='display:block;cursor:hand' onclick=\"Native('" + v.Caption + "','" + v.Productid + "')\">" + v.Caption + "</a></span>");
            //        sb.Append("</li>");
            //    }
            //    sb.Append("</ul>");
            //}
        }
 
        #endregion

        #region 创建产品规划树
        private string CreateProductLayoutTree()
        {
            //得到课程类型
            StringBuilder _strHtml = new StringBuilder();
            BDatPhraseDetail productTypeMgr = new BDatPhraseDetail();
            IList<DatPhraseDetail> ilist = productTypeMgr.GetDatPhraseDetailByClassValue("ProductType");
            _strHtml.Append("<div  id='" + this.ID + "' class='whitebg'>");
            _strHtml.Append("<ul>");
            _strHtml.Append("<li><a href='#'>"+DateTime.Now.Year.ToString()+"年"+"</a>");
            if (ilist != null && ilist.Count > 0)
            {
                //_strHtml.Append("<ul>");
                //添加产品类型
                foreach (DatPhraseDetail v in ilist)
                {
                    //_strHtml.Append("<li>");
                    //_strHtml.Append("<a href=\"#" + v.PhraseID + "\">" + v.PhraseText + "</a>");
                    //添加产品节点
                    addAllProduct(v.PhraseID, _strHtml);
                    //addProductLayout(v.PhraseID, _strHtml);
                    //_strHtml.Append("</li>");
                }
               // _strHtml.Append("</ul>");
            }
            _strHtml.Append("</li></ul>");
            _strHtml.Append("</div>");
            return _strHtml.ToString();

        }
        private void addAllProduct(Guid productTypeId, StringBuilder sb)
        {
            //BaseBussnies bll = new BaseBussnies();
            //IList<CrmProduct> ilist = bll.GetEntitys<CrmProduct>("TypeId='" + productTypeId + "'");
            //if (ilist != null && ilist.Count > 0)
            //{
            //    sb.Append("<ul>");
            //    foreach (CrmProduct v in ilist)
            //    {
            //        sb.Append("<li>");
            //        sb.Append("<span><a href=\"#" + v.Productid + "\" style='display:block;cursor:hand' onclick=\"Native('" + v.Caption + "','" + v.Productid + "')\">" + v.Caption + "</a></span>");
            //        addProductLayout(v.Productid, sb);
            //        sb.Append("</li>");
            //    }
            //    sb.Append("</ul>");
            //}
        }
        //添加产品节点到产品树
        private void addProductLayout(Guid productId, StringBuilder sb)
        {
            //BaseBussnies bll = new BaseBussnies();
            //IList<CrmProductLayout> ilist = bll.GetEntitys<CrmProductLayout>("ProductID='" + productId + "'");
            //if (ilist != null && ilist.Count > 0)
            //{
            //    sb.Append("<ul>");
            //    foreach (CrmProductLayout v in ilist)
            //    {
            //        sb.Append("<li>");
            //        sb.Append("<span><a href=\"#" + v.ID + "\" style='display:block;cursor:hand' onclick=\"Native('" + v.CourseLayoutName + "','" + v.ID + "')\">" + v.CourseLayoutName + "</a></span>");
            //        sb.Append("</li>");
            //    }
            //    sb.Append("</ul>");
            //}
        }

        #endregion

    }
}
